<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>入库管理</title>
<%@include file="../include/jqueryeasyui.jsp"%>
<script type="text/javascript">

function showCustomer(pcode){ 
    var parent$ = self.parent.$;      //找到父级DOM  
 
    	var text =pcode+"测量数据";
        var url="page.customerdata.ashx?pcode="+pcode;
		if (parent$("#tabs").tabs('exists', text)) {
			parent$('#tabs').tabs('select', text);
		} else {
			var content = '<div style="width:100%;height:100%;overflow:hidden;">'
					+ '<iframe src="'
					+ url
					+ '" scrolling="auto" style="width:100%;height:100%;border:0;" ></iframe></div>';

				parent$('#tabs').tabs('add', {
				title : text,
				content : content,
				closable : true
			});
		}
    }
    
    
function addpinlei(pcode){ 
    var parent$ = self.parent.$;      //找到父级DOM  
 
    	var text =pcode+"品类";
        var url="page.pinlei.ashx?pcode="+pcode;
		if (parent$("#tabs").tabs('exists', text)) {
			parent$('#tabs').tabs('select', text);
		} else {
			var content = '<div style="width:100%;height:100%;overflow:hidden;">'
					+ '<iframe src="'
					+ url
					+ '" scrolling="auto" style="width:100%;height:100%;border:0;" ></iframe></div>';

				parent$('#tabs').tabs('add', {
				title : text,
				content : content,
				closable : true
			});
		}
    }



	function doAdd(){
	
		$('#outputWindow').form('clear');
		$('#outputWindow *').trigger('blur');// 离焦
		$('#outputWindow').window("open").window('setTitle', '创建项目');
		$('#cPIDContract').val("-1");
	}
	
	function getQueryParams(queryParams) {  
		var searchcontent = $('#searchcontent').val();
		var sc_projectname = $('#sc_projectname').val();
	     queryParams.v_creatorName = searchcontent;  
	     queryParams.cPName = sc_projectname;  
	     return queryParams;  
	   
	 }  
	
	 //增加查询参数，重新加载表格  
    function reloadgrid() {  
  
        //查询参数直接添加在queryParams中      
        var queryParams = $('#grid').datagrid('options').queryParams;  
        getQueryParams(queryParams);  
        $('#grid').datagrid('options').queryParams = queryParams;  
        $("#grid").datagrid('load');  
    }  
	 
	function doSearch(){
		reloadgrid();
	}
	
	function doEdit(){
		
		var rowData = $('#grid').datagrid('getSelected');  
        if (rowData == null) {  
            $.messager.alert("提示", "请选择要修改的行！", "info");  
        } else{
        
	        $("input[name='cPIDContract']").val(rowData.cPIDContract);
			$("input[name='cPIDSerial']").val(rowData.cPIDSerial);
			$("input[name='cPName']").val(rowData.cPName);
		

			// 弹出窗口
			  
			$("#outputWindow").window('open').window('setTitle', '修改项目');
        } 
	}


	
	// 定义列
	var columns = [ [ {
		field : 'cPIDSerial',
		title : '项目代码',
		width : 120,
	},{
		field : 'cPName',
		title : '项目名称',
		width : 500,	
	}, {
		field : 'createTime',
		title : '创建时间',
		width : 160,
		formatter:formatterDate
	},{
		field : 'v_creatorName',
		title : '创建人',
		width : 160,
	}, {
		field : 'cPIDContract',
		title : '操作',
		width : 160,
		
		formatter:formatterId
	}  ] ];
	
	function formatterId(value,row,index) {
		var cPIDSerial = row.cPIDSerial;
		
		
		 return "<a href=# onclick=showCustomer(\'"+cPIDSerial+"\')>查看测量数据</a>"+"&nbsp;&nbsp;&nbsp;&nbsp;"; 
	
	}


	
	function formatterCaoZuo(value,row,index){
		if(row.iRIsDone==false){

			return "<a onclick=doProcess("+index+") href=#>处理</a>&nbsp;&nbsp;&nbsp;&nbsp;<a onclick=doDel("+index+") href=#>删除</a>";
		}else{
			return "";
		}
	}
	
	function doProcess(index){
	    $('#grid').datagrid('selectRow',index);// 关键在这里  
	    var row = $('#grid').datagrid('getSelected'); 
	    if(row){ 
 	    	//alert(row.iRId)
 			location.href="${pageContext.request.contextPath}/page.inputrulerdetails.ashx?iRId="+row.iRId;

		}
	}
	
	function doDel(index){
	    $('#grid').datagrid('selectRow',index);// 关键在这里  
	    var row = $('#grid').datagrid('getSelected'); 
	    if(row){ 
	/*     	$.messager.alert('消息','确认删除 当前记录？','info',function(){
	     	   
			})
			 */
		     $.messager.confirm("操作提示", "确认删除 当前记录？", function (data) {  
		            if (data) {  
		            	$.post("${pageContext.request.contextPath}/page.inputrulerdel.ashx?iRId="+row.iRId,function(data){
			    			
			    			if(data.status == "1"){
			    				// 成功
			    				$.messager.alert('消息','操作成功 ','info');
			    				reloadgrid();
			    				
			    			
			    			}else{
			    					//$.messager.alert('消息','<br>操作失败','info');
			    					data =new String(data).replace(' ', '');
			    					data=data.replace(' ', '')
									if(data.charAt(0)=='<'){
										$.messager.alert('消息','没有权限 ','info');
									}else{
										$.messager.alert('消息','操作失败 ','info');
									}
			    				
			    			}
			    				
			    		}); 
		            }  
		            else {  
		                 
		            }  
		        }); 


		}
	}
	
	
	
	function formatterDate(value,row,index){
		if(value==''||null==value){
			return '';
		}
		var now = new Date(value);  
		var year=now.getYear()+1900; 
		var month=now.getMonth()+1; 
		var date=now.getDate(); 
		var hour=now.getHours(); 
		var minute=now.getMinutes();
		minute= (minute > 9) ? minute=minute : minute='0'+minute;
		//var second=now.getSeconds(); 
		return year+"-"+month+"-"+date+" "+hour+":"+minute; 
	}
	
	 function formateroBIsDone(value,row,index){
		if(value==false){
			return "否";
		}else{
			return "是";
		}
	} 
	


	


	$(function(){
 		$('#add').click(doAdd);
 		$('#edit').click(doEdit);
		$('#search').click(doSearch);
		$('#downloadxls').click(doDownload);
	});
	
function doDownload(){	
		
		location.href="${pageContext.request.contextPath}/mingdan.xls";
	}
	$(function(){
		// 先将body隐藏，再显示，不会出现页面刷新效果
		$("body").css({visibility:"visible"});
		
		// 收派标准数据表格
		$('#grid').datagrid( {
			iconCls : 'icon-forward',
			fit : true,
			border : false,
			rownumbers : true,
			singleSelect:true,
			striped : true,
			toolbar : '#tb',
			url : "${pageContext.request.contextPath}/contract/page.list.ashx",
			idField : 'sId',
			columns : columns,
			pageList: [10,20,50,100],
			pagination:true,
			view:myview,
			emptyMsg:"<font size=5>暂无记录</font>"
			
		});
		
		//初始化员工窗口
		$('#outputWindow').window({
            title: '入库',
            width: 400,
            modal: true,
            shadow: true,
            closed: true,
            height: 400,
            resizable:false
            
        });
		
		
		
		//提交表单
		$('#save').click(function(){
		
				// 校验
				if($('#sform').form('validate')){
					// 1 、获得form 数据
					var params = $('#sform').serialize();
					// 2、将数据发送给服务器 
					$.post("${pageContext.request.contextPath}/contract/page.saveOrUpdate.ashx", params , function(data){
						if(data == "success"){
							// 成功
							$.messager.alert('消息','操作成功 ','info');
							// 关闭窗口
							$('#outputWindow').window('close');
							// 清除表单数据
							$('#outputWindow').form('clear');
							$('#outputWindow *').trigger('blur');// 离焦
							
							// 刷新表格数据 
							$('#grid').datagrid('reload');
						}else if(data == "pcodeconflict"){
							$.messager.alert('消息','项目代码重复','info');
						}
						else{
							data =new String(data);
							if(data.charAt(0)=='<'){
								$.messager.alert('消息','没有权限 ','info');
							}else{
								$.messager.alert('消息','操作失败 ','info');
							}
							
						}
							
					});
				}
				
			});	
		
		
	});
	
	
	
	var myview = $.extend({},$.fn.datagrid.defaults.view,{
		onAfterRender:function(target){
			$.fn.datagrid.defaults.view.onAfterRender.call(this,target);
			var opts = $(target).datagrid('options');
			var vc = $(target).datagrid('getPanel').children('div.datagrid-view');
			vc.children('div.datagrid-empty').remove();
			if (!$(target).datagrid('getRows').length){
				var d = $('<div class="datagrid-empty"></div>').html(opts.emptyMsg || 'no records').appendTo(vc);
				d.css({
					position:'absolute',
					left:0,
					top:50,
					width:'100%',
					textAlign:'center'
				});
			}
		}
	});


	
	
		
</script>	
</head>
<body class="easyui-layout" >
	<div region="center">
	
		<table id="grid">
		
		</table>
	</div>
	
	  
	
		<div id="tb" style="padding:5px;height:auto">
		<div style="margin-bottom:5px">
		<!-- 	<a href="#" id="add" class="easyui-linkbutton" iconCls="icon-add" plain="true" >增加</a>
 			<a href="#" id="edit" class="easyui-linkbutton" iconCls="icon-edit" plain="true">编辑</a> -->
 					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;项目名称: <input id="sc_projectname" class="easyui-textbox" style="width:200px">
 			
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;创建人: <input id="searchcontent" class="easyui-textbox" style="width:200px">
			<a href="#"  id="search" class="easyui-linkbutton" iconCls="icon-search">搜索</a>
			
		
		</div>
	</div>
	
</body>
</html>